﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ImageHandler;
using Stamp_For_Africa_Version_2.Models;
using Stamp_For_Africa_Version_2.Repositories;

namespace Stamp_For_Africa_Version_2.Controllers
{
  public class HomeController : Controller
  {
    public ActionResult Index()
    { 
      return View();
    }

    public ActionResult About()
    {
      return View();
    }

		public ActionResult Stamps()
		{
			return RedirectToAction("Index", "Stamps");
		}

		public ActionResult Management()
		{
			return RedirectToAction("Index", "Management");
		}

    
    
    [Authorize]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult FileUpload(StampImageUploadModel uploadedFileMeta)
    {

      try
      {
        var fileName = this.Server.MapPath("~/UserUploads/" + System.IO.Path.GetFileName(uploadedFileMeta.fileData.FileName));
        var nonRootedPath = "/UserUploads/" + System.IO.Path.GetFileName(uploadedFileMeta.fileData.FileName);
        uploadedFileMeta.fileData.SaveAs(fileName);
        return Json(new { Status = "OK", returnFile = fileName, serverPath = nonRootedPath });
      }
      catch (Exception ex)
      {
        return Json(new { Status = "Failed" });
      }

    }
  }
}
